<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>soy_testhelper.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_soy_soy_testhelper.js.html">soy_testhelper.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Provides test helpers for Soy tests.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>/** @suppress {extraProvide} */
<a name="line20"></a>goog.provide(&#39;goog.soy.testHelper&#39;);
<a name="line21"></a>goog.setTestOnly(&#39;goog.soy.testHelper&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.dom&#39;);
<a name="line24"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line25"></a>goog.require(&#39;goog.i18n.bidi.Dir&#39;);
<a name="line26"></a>goog.require(&#39;goog.soy.data.SanitizedContent&#39;);
<a name="line27"></a>goog.require(&#39;goog.soy.data.SanitizedContentKind&#39;);
<a name="line28"></a>goog.require(&#39;goog.string&#39;);
<a name="line29"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line30"></a>
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>/**
<a name="line34"></a> * Instantiable subclass of SanitizedContent.
<a name="line35"></a> *
<a name="line36"></a> * This is a spoof for sanitized content that isn&#39;t robust enough to get
<a name="line37"></a> * through Soy&#39;s escaping functions but is good enough for the checks here.
<a name="line38"></a> *
<a name="line39"></a> * @constructor
<a name="line40"></a> * @param {string} content The text.
<a name="line41"></a> * @param {goog.soy.data.SanitizedContentKind} kind The kind of safe content.
<a name="line42"></a> * @extends {goog.soy.data.SanitizedContent}
<a name="line43"></a> */
<a name="line44"></a>function SanitizedContentSubclass(content, kind) {
<a name="line45"></a>  // IMPORTANT! No superclass chaining to avoid exception being thrown.
<a name="line46"></a>  this.content = content;
<a name="line47"></a>  this.contentKind = kind;
<a name="line48"></a>}
<a name="line49"></a>goog.inherits(SanitizedContentSubclass, goog.soy.data.SanitizedContent);
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>function makeSanitizedContent(content, kind) {
<a name="line53"></a>  return new SanitizedContentSubclass(content, kind);
<a name="line54"></a>}
<a name="line55"></a>
<a name="line56"></a>
<a name="line57"></a>
<a name="line58"></a>//
<a name="line59"></a>// Fake Soy-generated template functions.
<a name="line60"></a>//
<a name="line61"></a>
<a name="line62"></a>var example = {};
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>example.textNodeTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line66"></a>  assertNotNull(opt_data);
<a name="line67"></a>  assertNotUndefined(opt_data);
<a name="line68"></a>  return goog.string.htmlEscape(opt_data.name);
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>example.singleRootTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line73"></a>  assertNotNull(opt_data);
<a name="line74"></a>  assertNotUndefined(opt_data);
<a name="line75"></a>  return &#39;&lt;span&gt;&#39; + goog.string.htmlEscape(opt_data.name) + &#39;&lt;/span&gt;&#39;;
<a name="line76"></a>};
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>example.multiRootTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line80"></a>  assertNotNull(opt_data);
<a name="line81"></a>  assertNotUndefined(opt_data);
<a name="line82"></a>  return &#39;&lt;div&gt;Hello&lt;/div&gt;&lt;div&gt;&#39; + goog.string.htmlEscape(opt_data.name) +
<a name="line83"></a>      &#39;&lt;/div&gt;&#39;;
<a name="line84"></a>};
<a name="line85"></a>
<a name="line86"></a>
<a name="line87"></a>example.injectedDataTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line88"></a>  assertNotNull(opt_data);
<a name="line89"></a>  assertNotUndefined(opt_data);
<a name="line90"></a>  return goog.string.htmlEscape(opt_data.name) +
<a name="line91"></a>      goog.string.htmlEscape(opt_injectedData.name);
<a name="line92"></a>};
<a name="line93"></a>
<a name="line94"></a>
<a name="line95"></a>example.noDataTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line96"></a>  assertNotNull(opt_data);
<a name="line97"></a>  assertNotUndefined(opt_data);
<a name="line98"></a>  return &#39;&lt;div&gt;Hello&lt;/div&gt;&#39;;
<a name="line99"></a>};
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>example.sanitizedHtmlTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line103"></a>  // Test the SanitizedContent constructor.
<a name="line104"></a>  var sanitized = makeSanitizedContent(&#39;Hello &lt;b&gt;World&lt;/b&gt;&#39;,
<a name="line105"></a>      goog.soy.data.SanitizedContentKind.HTML);
<a name="line106"></a>  sanitized.contentDir = goog.i18n.bidi.Dir.LTR;
<a name="line107"></a>  return sanitized;
<a name="line108"></a>};
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>example.sanitizedHtmlAttributesTemplate =
<a name="line112"></a>    function(opt_data, opt_sb, opt_injectedData) {
<a name="line113"></a>  return makeSanitizedContent(&#39;foo=&quot;bar&quot;&#39;,
<a name="line114"></a>      goog.soy.data.SanitizedContentKind.ATTRIBUTES);
<a name="line115"></a>};
<a name="line116"></a>
<a name="line117"></a>
<a name="line118"></a>example.sanitizedCssTemplate =
<a name="line119"></a>    function(opt_data, opt_sb, opt_injectedData) {
<a name="line120"></a>  return makeSanitizedContent(&#39;display:none&#39;,
<a name="line121"></a>      goog.soy.data.SanitizedContentKind.CSS);
<a name="line122"></a>};
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>example.unsanitizedTextTemplate =
<a name="line126"></a>    function(opt_data, opt_sb, opt_injectedData) {
<a name="line127"></a>  return makeSanitizedContent(&#39;I &lt;3 Puppies &amp; Kittens&#39;,
<a name="line128"></a>      goog.soy.data.SanitizedContentKind.TEXT);
<a name="line129"></a>};
<a name="line130"></a>
<a name="line131"></a>
<a name="line132"></a>example.templateSpoofingSanitizedContentString =
<a name="line133"></a>    function(opt_data, opt_sb, opt_injectedData) {
<a name="line134"></a>  return makeSanitizedContent(&#39;Hello World&#39;,
<a name="line135"></a>      // This is to ensure we&#39;re using triple-equals against a unique Javascript
<a name="line136"></a>      // object.  For example, in Javascript, consider ({}) == &#39;[Object object]&#39;
<a name="line137"></a>      // is true.
<a name="line138"></a>      goog.soy.data.SanitizedContentKind.HTML.toString());
<a name="line139"></a>};
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>example.tableRowTemplate = function(opt_data, opt_sb, opt_injectedData) {
<a name="line143"></a>  return &#39;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&#39;;
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>example.colGroupTemplateCaps = function(opt_data, opt_sb, opt_injectedData) {
<a name="line148"></a>  return &#39;&lt;COLGROUP&gt;&lt;/COLGROUP&gt;&#39;;
<a name="line149"></a>};
<a name="line150"></a>
<a name="line151"></a>
<a name="line152"></a>//
<a name="line153"></a>// Test helper functions.
<a name="line154"></a>//
<a name="line155"></a>
<a name="line156"></a>
<a name="line157"></a>/**
<a name="line158"></a> * Retrieves the content of document fragment as HTML.
<a name="line159"></a> * @param {Node} fragment The document fragment.
<a name="line160"></a> * @return {string} Content of the document fragment as HTML.
<a name="line161"></a> */
<a name="line162"></a>function fragmentToHtml(fragment) {
<a name="line163"></a>  var testDiv = goog.dom.createElement(goog.dom.TagName.DIV);
<a name="line164"></a>  testDiv.appendChild(fragment);
<a name="line165"></a>  return elementToInnerHtml(testDiv);
<a name="line166"></a>}
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * Retrieves the content of an element as HTML.
<a name="line171"></a> * @param {Element} elem The element.
<a name="line172"></a> * @return {string} Content of the element as HTML.
<a name="line173"></a> */
<a name="line174"></a>function elementToInnerHtml(elem) {
<a name="line175"></a>  var innerHtml = elem.innerHTML;
<a name="line176"></a>  if (goog.userAgent.IE) {
<a name="line177"></a>    innerHtml = innerHtml.replace(/DIV/g, &#39;div&#39;).replace(/\s/g, &#39;&#39;);
<a name="line178"></a>  }
<a name="line179"></a>  return innerHtml;
<a name="line180"></a>}
</pre>


</body>
</html>
